package com.jinzecloud.reportapproval.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.template.TemplateException;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.Pictures;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.jinzecloud.reportapproval.bean.*;
import com.jinzecloud.reportapproval.enums.AuditRoleEnums;
import com.jinzecloud.reportapproval.enums.StateEnum;
import com.jinzecloud.reportapproval.enums.TableEnums;
import com.jinzecloud.reportapproval.dto.AdminDto;
import com.jinzecloud.reportapproval.dto.Param;
import com.jinzecloud.reportapproval.mapper.AdminMapper;
import com.jinzecloud.reportapproval.mapper.ProductInfoMapper;
import com.jinzecloud.reportapproval.service.*;
import com.jinzecloud.reportapproval.utils.*;
import com.jinzecloud.reportapproval.vo.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.io.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;


@Service("productInfoService")
public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, ProductInfo> implements ProductInfoService {
    @Autowired
    private ProCoveredModelService proCoveredModelService;
    @Autowired
    private ProTecSpecServiceImpl proTecSpecService;
    @Autowired
    private ProductInfoMapper productInfoMapper;
    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private CoverService coverService;
    @Autowired
    private FileUploadUtil fileUploadUtil;
    @Autowired
    private ProductSpecificationService productSpecificationService;
    @Autowired
    private ProductSpecificationDataService productSpecificationDataService;
    @Autowired
    private ProductSpecificationInfoService productSpecificationInfoService;

    @Override
    public PageUtils queryPage(Param param) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String adminUserName = authentication.getName();
        MPJLambdaWrapper<Admin> adminWrapper = new MPJLambdaWrapper<>();
        adminWrapper
                .select(Admin::getAdId, Admin::getAdUserName, Admin::getAdName)
                .select(RoleEntity::getRoleName)
                .leftJoin(RoleUserEntity.class, RoleUserEntity::getUserId, Admin::getAdId)
                .leftJoin(RoleEntity.class, RoleEntity::getRoleId, RoleUserEntity::getRoleId)
                .eq(Admin::getAdUserName, adminUserName);
        String pageSize = param.getPage();
        String limit = param.getLimit();
        String key = param.getKey();
        Map<String, Object> params = new HashMap<>();
        params.put("page", pageSize);
        params.put("limit", limit);
        MPJLambdaWrapper<ProductInfo> reportMPJLambdaWrapper = new MPJLambdaWrapper<>();
        reportMPJLambdaWrapper.selectAll(ProductInfo.class);
        if (!StringUtils.isEmpty(key)) {
            reportMPJLambdaWrapper.eq(Report::getId, key).or()
                    .like(Report::getProductName, key).or();
        }
        IPage<ProductInfoVoes> page = productInfoMapper.selectJoinPage(
                new Page<>(Long.parseLong((String) params.get("page")), Long.parseLong((String) params.get("limit"))),
                ProductInfoVoes.class,
                reportMPJLambdaWrapper
        );
        PageUtils pageUtils = new PageUtils(page);
        List<ProductInfoVoes> records = page.getRecords();
        List<ProductInfoVoes> collect = records.stream()
                .peek(productInfoVo -> {
                    String reprotStatus = productInfoVo.getReprotStatus();
//                    productInfoVo.setApprovalOpinion(StateEnum.getStateEnum(Integer.parseInt(reprotStatus)).getDesc());
                }).collect(Collectors.toList());
        pageUtils.setList(collect);
        return pageUtils;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public R saveProductInfo(ProductInfoVo productInfoVo) {
        ProductInfo productInfo = new ProductInfo();
        BeanUtils.copyProperties(productInfoVo, productInfo);
        productInfo.setPdfPath("").setProductFilePath("");
        productInfo.setReprotStatus(String.valueOf(StateEnum.UN_SUBMIT.getState()));
        QueryWrapper<ProductInfo> productInfoQueryWrapper = new QueryWrapper<>();
        productInfoQueryWrapper.eq("product_number", productInfoVo.getProductNumber());
        List<ProductInfo> list = list(productInfoQueryWrapper);
        if (list.size() >= 1) return R.error("编号：" + productInfoVo.getProductNumber() + "已存在，请勿重复添加！");
        save(productInfo);
//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        String adminUserName = authentication.getName();
//        QueryWrapper<Admin> adminQueryWrapper = new QueryWrapper<>();
//        adminQueryWrapper.eq("ad_user_name", adminUserName);
//        Admin admin = adminMapper.selectOne(adminQueryWrapper);
//        ProductInfo productInfo = new ProductInfo();
//        BeanUtils.copyProperties(productInfoVo, productInfo);
//        productInfo.setProductIdentificationClass("推广鉴定报告");
//        productInfo.setReprotStatus("1");
//        productInfo.setReportWriter(admin.getAdSignature());
//        this.save(productInfo);
//        List<ProTecSpecVo> proTecSpecVo = productInfoVo.getProTecSpecVo();
//        List<ProTecSpec> collect = proTecSpecVo.stream().map(proTecSpecVo1 -> {
//            ProTecSpec proTecSpec = new ProTecSpec();
//            BeanUtils.copyProperties(proTecSpecVo1, proTecSpec);
//            proTecSpec.setProductInfoId(productInfo.getId());
//            return proTecSpec;
//        }).collect(Collectors.toList());
//        List<ProCoveredModelVo> proCoveredModelVo = productInfoVo.getProCoveredModelVo();
//        List<ProCoveredModel> collect1 = proCoveredModelVo.stream().map(proCoveredModelVo1 -> {
//            ProCoveredModel proCoveredModel = new ProCoveredModel();
//            BeanUtils.copyProperties(proCoveredModelVo1, proCoveredModel);
//            proCoveredModel.setProductInfoId(productInfo.getId());
//            return proCoveredModel;
//        }).collect(Collectors.toList());
//        ProCoveredModel proCoveredModel = new ProCoveredModel();
//        BeanUtils.copyProperties(proCoveredModelVo, proCoveredModel);
//        proCoveredModel.setProductInfoId(productInfo.getId());
//        proTecSpecService.saveBatch(collect);
//        proCoveredModelService.saveBatch(collect1);
        return R.ok();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateByIdProductInfoVo(ProductInfoVo productInfoVo) {
//        ProductInfo productInfo = new ProductInfo();
//        BeanUtils.copyProperties(productInfoVo, productInfo);
//        productInfo.setReprotStatus(String.valueOf(StateEnum.UN_SUBMIT.getState()));
//        List<ProTecSpecVo> proTecSpecVo = productInfoVo.getProTecSpecVo();
//        List<ProTecSpec> collect = proTecSpecVo.stream().map(proTecSpecVo1 -> {
//            ProTecSpec proTecSpec = new ProTecSpec();
//            BeanUtils.copyProperties(proTecSpecVo1, proTecSpec);
//            proTecSpec.setProductInfoId(productInfo.getId());
//            return proTecSpec;
//        }).collect(Collectors.toList());
//        List<ProCoveredModelVo> proCoveredModelVo = productInfoVo.getProCoveredModelVo();
//        List<ProCoveredModel> collect1 = proCoveredModelVo.stream().map(proCoveredModelVo1 -> {
//            ProCoveredModel proCoveredModel = new ProCoveredModel();
//            BeanUtils.copyProperties(proCoveredModelVo1, proCoveredModel);
//            proCoveredModel.setProductInfoId(productInfo.getId());
//            return proCoveredModel;
//        }).collect(Collectors.toList());
//        productInfo.setProductFilePath("");
//        productInfo.setPdfPath("");
//        this.updateById(productInfo);
//        proTecSpecService.updateBatchById(collect);
//        proCoveredModelService.updateBatchById(collect1);
        ProductInfo productInfo = new ProductInfo();
        BeanUtils.copyProperties(productInfoVo, productInfo);
        productInfo.setPdfPath("").setProductFilePath("");
        updateById(productInfo);
    }

    @Override
    public void removeByIdsProductInfoVo(List<Integer> list) {
        QueryWrapper<ProductInfo> productInfoQueryWrapper = new QueryWrapper<>();
        QueryWrapper<ProTecSpec> proTecSpecQueryWrapper = new QueryWrapper<>();
        QueryWrapper<ProCoveredModel> proCoveredModelQueryWrapper = new QueryWrapper<>();
        for (Integer i : list) {
            productInfoQueryWrapper.eq("id", i);
            ProductInfo productInfo = this.getOne(productInfoQueryWrapper);
            proTecSpecQueryWrapper.eq("product_info_id", productInfo.getId());
            List<ProTecSpec> list1 = proTecSpecService.list(proTecSpecQueryWrapper);
            proCoveredModelQueryWrapper.eq("product_info_id", productInfo.getId());
            List<ProCoveredModel> list2 = proCoveredModelService.list(proCoveredModelQueryWrapper);
            this.removeById(productInfo.getId());
            proTecSpecService.removeBatchByIds(list1);
            proCoveredModelService.removeBatchByIds(list2);
        }
    }

    @Override
    public ProductInfoVos getByIdProductInfoVo(Integer id) {
        ProductInfoVos productInfoVos = new ProductInfoVos();
        QueryWrapper<ProductInfo> productInfoQueryWrapper = new QueryWrapper<>();
        productInfoQueryWrapper.eq("id", id);
        ProductInfo productInfo = this.getOne(productInfoQueryWrapper);
        BeanUtils.copyProperties(productInfo, productInfoVos);
        QueryWrapper<ProTecSpec> proTecSpecQueryWrapper = new QueryWrapper<>();
        proTecSpecQueryWrapper.eq("product_info_id", productInfo.getId());
        List<ProTecSpec> list = proTecSpecService.list(proTecSpecQueryWrapper);
        List<ProTecSpecVo> collect = list.stream().map(proTecSpec -> {
            ProTecSpecVo proTecSpecVo = new ProTecSpecVo();
            BeanUtils.copyProperties(proTecSpec, proTecSpecVo);
            return proTecSpecVo;
        }).collect(Collectors.toList());
        productInfoVos.setProTecSpecVo(collect);
        QueryWrapper<ProCoveredModel> proCoveredModelQueryWrapper = new QueryWrapper<>();
        proCoveredModelQueryWrapper.eq("product_info_id", productInfo.getId());
        List<ProCoveredModel> list1 = proCoveredModelService.list(proCoveredModelQueryWrapper);
        List<ProCoveredModelVo> collect1 = list1.stream().map(proCoveredModel -> {
            ProCoveredModelVo proCoveredModelVo = new ProCoveredModelVo();
            BeanUtils.copyProperties(proCoveredModel, proCoveredModelVo);
            return proCoveredModelVo;
        }).collect(Collectors.toList());
        productInfoVos.setProCoveredModelVo(collect1);
        return productInfoVos;
    }

    @Override
    public PageUtils queryPageCheckList(Param param) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String adminUserName = authentication.getName();
        MPJLambdaWrapper<Admin> adminWrapper = new MPJLambdaWrapper<>();
        adminWrapper
                .select(Admin::getAdId, Admin::getAdUserName, Admin::getAdName)
                .select(RoleEntity::getRoleName)
                .leftJoin(RoleUserEntity.class, RoleUserEntity::getUserId, Admin::getAdId)
                .leftJoin(RoleEntity.class, RoleEntity::getRoleId, RoleUserEntity::getRoleId)
                .eq(Admin::getAdUserName, adminUserName);
        List<AdminDto> adminDos = adminMapper.selectJoinList(AdminDto.class, adminWrapper);
        String pageSize = param.getPage();
        String limit = param.getLimit();
        String key = param.getKey();
        Map<String, Object> params = new HashMap<>();
        params.put("page", pageSize);
        params.put("limit", limit);
        MPJLambdaWrapper<ProductInfo> productInfoMPJLambdaWrapper = new MPJLambdaWrapper<>();
        productInfoMPJLambdaWrapper
                .selectAll(ProductInfo.class)
                .selectAll(ProTecSpec.class)
                .selectAll(ProCoveredModel.class)
                .leftJoin(ProTecSpec.class, ProTecSpec::getProductInfoId, ProductInfo::getId)
                .leftJoin(ProCoveredModel.class, ProCoveredModel::getProductInfoId, ProductInfo::getId);
        if (!StringUtils.isEmpty(key)) {
            productInfoMPJLambdaWrapper.eq(ProductInfo::getId, key).or()
                    .like(ProductInfo::getProductName, key).or()
                    .like(ProductInfo::getModel, key).or()
                    .like(ProductInfo::getManufacturer, key).or()
                    .like(ProductInfo::getFactory, key);
        }
        if (!StringUtils.isEmpty(key)) {
            productInfoMPJLambdaWrapper.eq(Report::getId, key).or()
                    .like(Report::getProductName, key).or();
        }
        Set<Integer> stateSet = adminDos.stream().map(adminDo ->
                StateEnum.getStateEnumByAuditRole(adminDo.getRoleCode()).getState()).collect(Collectors.toSet());
        if (stateSet.contains(StateEnum.UN_SUBMIT.getState())) {
            // TODO 只能看见自己编辑的逻辑
//            productInfoMPJLambdaWrapper.and(wrapper -> wrapper.eq(ProductInfo::getReprotStatus, StateEnum.SUBMIT.getState()).eq(ProductInfo::get));
            stateSet.add(StateEnum.APPROVAL_PASS.getState());
//            stateSet.remove(StateEnum.SUBMIT.getState());
        }
        productInfoMPJLambdaWrapper.in(ProductInfo::getReprotStatus, stateSet);

        IPage<ProductInfoCheckVo> page = productInfoMapper.selectJoinPage(
                new Page<ProductInfoCheckVo>(Long.parseLong((String) params.get("page")), Long.parseLong((String) params.get("limit"))),
                ProductInfoCheckVo.class,
                productInfoMPJLambdaWrapper
        );
        PageUtils pageUtils = new PageUtils(page);

        List<ProductInfoCheckVo> records = page.getRecords();
        List<ProductInfoCheckVo> collect = records.stream()
                .map(productInfoVo -> {
                    String reprotStatus = productInfoVo.getReprotStatus();
                    productInfoVo.setApprovalOpinion(AuditUtil.getStateText(TableEnums.REPORT_AND_PRODUCT_INFO.getTableName(), Integer.parseInt(reprotStatus)).getDesc());
                    return productInfoVo;
                }).collect(Collectors.toList());
        pageUtils.setList(collect);
        return pageUtils;
    }

    @Override
    public R updateApprovalOpinion(ProductInfoUpdateCheckVo productInfoUpdateCheckVo) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        ProductInfo productInfo = this.getById(productInfoUpdateCheckVo.getId());
        int state = Integer.parseInt(productInfo.getReprotStatus());
        List<AdminDto> adminDos = AuditUtil.getAdminDto(authentication.getName());
        if (CollectionUtil.isEmpty(adminDos)) return R.error("您没有审核权限！");
        if (!productInfoUpdateCheckVo.isReprotStatus()) {
            updateById(productInfo.setReprotStatus(String.valueOf(StateEnum.APPROVAL_NOT_PASS.getState()))
                    .setApprovalOpinion(productInfoUpdateCheckVo.getAuditOpinion())
                    .setDateOfApproval(DateUtil.date()));
            return R.ok();
        }
        StateEnum currentAuditState = AuditUtil.getStateText(TableEnums.REPORT_AND_PRODUCT_INFO.getTableName(), state);
        Integer nextAuditStateIndex = AuditUtil.getNextAuditState(TableEnums.REPORT_AND_PRODUCT_INFO.getTableName(), state, adminDos.stream().map(AdminDto::getRoleCode).toList());
        AdminDto adminDto = adminDos.stream().filter(a -> StrUtil.equals(a.getRoleCode(), currentAuditState.getAuditRole()))
                .findFirst().orElse(null);
        if (adminDto == null || nextAuditStateIndex == null) return R.error("您没有审核权限！");
        if (StrUtil.equals(adminDto.getRoleCode(), AuditRoleEnums.WRITER.getCode())) productInfo.setReportWriter(adminDto.getAdSignature());
        if (StrUtil.equals(adminDto.getRoleCode(), AuditRoleEnums.APPROVER.getCode())) productInfo.setApprover(adminDto.getAdSignature());
        if (StrUtil.equals(adminDto.getRoleCode(), AuditRoleEnums.AUDITOR.getCode())) productInfo.setAuditor(adminDto.getAdSignature());
        if (StrUtil.equals(adminDto.getRoleCode(), AuditRoleEnums.PRINCIPAL.getCode())) productInfo.setProjectLeader(adminDto.getAdSignature());
        if (StrUtil.equals(adminDto.getRoleCode(), AuditRoleEnums.CHECKER.getCode())) productInfo.setReportChecker(adminDto.getAdSignature());
        productInfo.setReprotStatus(String.valueOf(nextAuditStateIndex))
                .setAuditor(adminDto.getAdSignature())
                .setApprovalOpinion(productInfoUpdateCheckVo.getAuditOpinion())
                .setDateOfApproval(DateUtil.date());
        updateById(productInfo);
        return R.ok();
    }

    @Override
    public String fileDownload(String id) throws TemplateException {
        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
        ProductInfo productInfo = this.getById(id);
        JSONObject data = JSONObject.parseObject(JSONObject.toJSONString(productInfo));
        data.put("pictureProductName", StrUtil.isNotEmpty(data.getString("pictureProductName")) ? Pictures.ofUrl(data.getString("pictureProductName")).size(400, 300).create() : null);
        ProductSpecification productSpecification = productSpecificationService.getOne(
                new LambdaQueryWrapper<ProductSpecification>().eq(ProductSpecification::getProjectNumber, productInfo.getProductNumber())
        );
        if (productSpecification != null) {
            List<ProductSpecificationData> productSpecificationData = productSpecificationDataService.list();
            List<ProductSpecificationInfo> productSpecificationInfoList = productSpecificationInfoService.list(new LambdaQueryWrapper<ProductSpecificationInfo>().eq(ProductSpecificationInfo::getProductSpecificationId, productSpecification.getId()));
            if (CollectionUtil.isNotEmpty(productSpecificationInfoList)) {
                Map<String, ProductSpecificationInfo> productSpecificationInfoMap = productSpecificationInfoList.stream().collect(Collectors.toMap(ProductSpecificationInfo::getCharacteristic, Function.identity(), (k1, k2) -> k1));
                JSONArray array = new JSONArray();
                AtomicInteger i = new AtomicInteger(1);
                productSpecificationData.forEach(item -> {
                    JSONObject obj = new JSONObject();
                    obj.put("key", item.getCharacteristic());
                    obj.put("value", Optional.ofNullable(productSpecificationInfoMap.get(item.getCharacteristic())).map(ProductSpecificationInfo::getDesignValue).orElse(null));
                    obj.put("unit", item.getUnit());
                    obj.put("project", item.getProject());
                    obj.put("index", i.getAndIncrement());
                    array.add(obj);
                });
                data.put("productSpecificationData", array);
            }
        }
        File tempFile = WordUtil.getWordFile("template/productInfo1.docx", data, Configure.builder()
                .bind("productSpecificationData", policy));
        if (tempFile == null) return null;
        String fileName = "农业机械推广鉴定报告";
        String filePath = fileUploadUtil.getUploadFilePath("temp") + productInfo.getProductName() + fileName;
        String savePath = RequestUtils.getBasePath(request) + "upload/temp/" + productInfo.getProductName() + fileName;
        FileUtil.copy(tempFile, new File(filePath + ".docx"), true);
        PDFUtil.WordToPdf(tempFile, new File(filePath + ".pdf"));
        this.update(new LambdaUpdateWrapper<ProductInfo>().set(ProductInfo::getProductFilePath, savePath + ".docx").set(ProductInfo::getPdfPath, savePath + ".pdf").eq(ProductInfo::getId, id));
        return RequestUtils.getBasePath(request) + "upload/temp/" + productInfo.getProductName() + fileName + ".docx";
    }

    @Override
    public R fileUplod(String id, MultipartFile file) {
        String s = "";
        if (FileUtil.getSuffix(file.getOriginalFilename()).equals("docx")) {
            s = fileUploadUtil.validateFile(file, "WD");
        } else {
            s = fileUploadUtil.validateFile(file, "TP");
        }

        if (s != null) {
            return R.error(s);
        }
        String fileName = null;
        try {
            String suffix = cn.hutool.core.io.FileUtil.getSuffix(file.getOriginalFilename());
            fileName = StrUtil.uuid().replaceAll("-", "") + "." + suffix;
            String path = fileUploadUtil.getUploadFilePath("tp") + fileName;
            file.transferTo(FileUtil.file(path));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return R.ok().put("data", RequestUtils.getBasePath(request) + "upload/tp/" + fileName);
    }

    @Override
    public ProductInfoExportVoVo getByIdproductInfoExportVo(Integer id) {
        ProductInfo productInfo = this.getById(id);
        ProductInfoExportVoVo productInfoExportVoVo = new ProductInfoExportVoVo();
        BeanUtils.copyProperties(productInfo, productInfoExportVoVo);
        QueryWrapper<ProTecSpec> proTecSpecVoQueryWrapper = new QueryWrapper<>();
        proTecSpecVoQueryWrapper.eq("product_info_id", productInfo.getId());
        List<ProTecSpec> list = proTecSpecService.list(proTecSpecVoQueryWrapper);
        List<ProTecSpecVo> collect = list.stream().map(proTecSpec -> {
            ProTecSpecVo proTecSpecVo = new ProTecSpecVo();
            BeanUtils.copyProperties(proTecSpec, proTecSpecVo);
            return proTecSpecVo;
        }).collect(Collectors.toList());
        productInfoExportVoVo.setProTecSpecVo(collect);
        QueryWrapper<ProCoveredModel> proCoveredModelQueryWrapper = new QueryWrapper<>();
        proCoveredModelQueryWrapper.eq("product_info_id", productInfo.getId());
        List<ProCoveredModel> list1 = proCoveredModelService.list(proCoveredModelQueryWrapper);
        List<ProCoveredModelVo> collect1 = list1.stream().map(proCoveredModel -> {
            ProCoveredModelVo proCoveredModelVo = new ProCoveredModelVo();
            BeanUtils.copyProperties(proCoveredModel, proCoveredModelVo);
            return proCoveredModelVo;
        }).collect(Collectors.toList());
        productInfoExportVoVo.setProCoveredModelVo(collect1);
        return productInfoExportVoVo;
    }

    @Override
    public String getProductFilePath(String id) {
        ProductInfo productInfo =  this.getById(id);
//        if (StrUtil.isEmpty(productInfo.getProductFilePath()) || StrUtil.isEmpty(productInfo.getPdfPath())){
            fileDownload(id);
            productInfo = getById(id);
            return productInfo.getPdfPath();
//        }
//        return productInfo.getPdfPath();
    }

    @Override
    public String getProductFileWordPath(String id) {
        ProductInfo productInfo =  this.getById(id);
//        if (StrUtil.isEmpty(productInfo.getProductFilePath()) || StrUtil.isEmpty(productInfo.getPdfPath())){
        fileDownload(id);
        productInfo = getById(id);
        return productInfo.getProductFilePath();
//        }
//        return productInfo.getPdfPath();
    }
}